﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using Telerik.Examples.WinControls.ListView.CustomItems;
using Telerik.WinControls;

namespace LogViewApp
{
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();

            this.radListView1.ItemSize = new Size(300, 400);
            this.radListView1.AllowArbitraryItemHeight = true;
            this.radListView1.ItemSpacing = 0;
            this.radListView1.EnableKineticScrolling = true;

            this.radListView1.ListViewElement.ViewElement.ViewElement.Margin = new Padding(0, 0, 0, 0);
            this.radListView1.ListViewElement.ViewElement.Orientation = Orientation.Horizontal; 
        }

        private void RadForm1_Load(object sender, EventArgs e)
        {
            //this.radListView1.DataSource = new DataTable();

            DataTable dt = CreateDataTable();
            int i = 1;
            foreach (string file in Directory.GetFiles(@"Photos\", "*.jpg"))
            {
                Image img = Image.FromFile(file);
                DataRow row = dt.NewRow();
                row["Image"] = img;
                row["AlbumName"] = "AlbumName"+(i++);
                row["ArtistName"] = "ArtistName" + (i++);
                row["Rating"] = 1.0;

                dt.Rows.Add(row);
                break;
            } 

            this.radListView1.DataSource = dt;
        }

        private DataTable CreateDataTable()
        {
            DataTable dt = new DataTable();
            DataColumn cl = new DataColumn();
            cl.DataType = typeof(Image);
            cl.ColumnName = "Image";
            dt.Columns.Add(cl);
            cl = new DataColumn();
            cl.DataType = typeof(string);
            cl.ColumnName = "AlbumName";
            dt.Columns.Add(cl);
            cl = new DataColumn();
            cl.DataType = typeof(string);
            cl.ColumnName = "ArtistName";
            dt.Columns.Add(cl);
            cl = new DataColumn();
            cl.DataType = typeof(int);
            cl.ColumnName = "Rating";
            dt.Columns.Add(cl);

            return dt;
        }

        private void radListView1_VisualItemCreating(object sender, Telerik.WinControls.UI.ListViewVisualItemCreatingEventArgs e)
        {
            e.VisualItem = new CustomVisualItem();
        } 
    }
}
